package com.wh.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wh.model.WorkProject;
import com.legend.security.Authority;
import com.legend.security.PermissionType;
import com.wh.service.IExt.IWorkProjectService;
import com.wh.service.impl.WorkProjectService;
import com.legend.utils.*;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

import java.util.HashMap;
import java.util.Map;

/*
*author:徐洪昌
*blog:http://cnblogs.com/xusir
*datetime:2014-07-23 11:12:26
*/
@Controller
@RequestMapping(value = "/api/project")
public class WorkProjectController {
    Logger log = Logger.getLogger(WorkProjectController.class);
    private static final String MODULECODE = "WorkProject";

    @Authority(moduleCode = MODULECODE, permissionType = PermissionType.View)
    @RequestMapping(value = "new", method = RequestMethod.POST)
    @ResponseBody
    public String newPro(HttpServletRequest request) {
        String data = Request.getData(request);
        WorkProject project = JSONObject.parseObject(data, WorkProject.class);
        IWorkProjectService service = WorkProjectService.getInstance();
        ReturnResult result = service.insertByModel(project);
        return JSONObject.toJSONString(result);
    }
    @Authority(moduleCode = MODULECODE, permissionType = PermissionType.View)
    @RequestMapping(value = "getList/{teamId}/{pageIndex}/{pageSize}", method = RequestMethod.GET)
    @ResponseBody
    public String getList(@PathVariable("teamId") String teamId,@PathVariable("pageIndex") int pageIndex, @PathVariable("pageSize") int pageSize) {
        Map<String,Object> map=new HashMap<String, Object>();
        if (!"all".equals(teamId))
        map.put("teamId",teamId);
        IWorkProjectService service = WorkProjectService.getInstance();
        ReturnResult result = service.selectByMap(pageIndex,pageSize,map);
        return JSONObject.toJSONString(result);
    }

}